POST
/
1
/
indexes
/
{indexName}
/
rules
/
batch
// Initialize the client
var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));

// Call the API
var response = await client.SaveRulesAsync(
  "<YOUR_INDEX_NAME>",
  new List<Rule>
  {
    new Rule
    {
      ObjectID = "a-rule-id",
      Conditions = new List<Condition>
      {
        new Condition { Pattern = "smartphone", Anchoring = Enum.Parse<Anchoring>("Contains") },
      },
      Consequence = new Consequence
      {
        Params = new ConsequenceParams { Filters = "brand:apple" },
      },
    },
    new Rule
    {
      ObjectID = "a-second-rule-id",
      Conditions = new List<Condition>
      {
        new Condition { Pattern = "apple", Anchoring = Enum.Parse<Anchoring>("Contains") },
      },
      Consequence = new Consequence
      {
        Params = new ConsequenceParams { Filters = "brand:samsung" },
      },
    },
  },
  false,
  true
);
// >LOG
{
  "taskID": 1514562690001,
  "updatedAt": "2023-07-04T12:49:15Z"
}

Authorizations

x-algolia-application-id
string
header
required

Your Algolia application ID.

x-algolia-api-key
string
header
required

Your Algolia API key with the necessary permissions to make the request. Permissions are controlled through access control lists (ACL) and access restrictions. The required ACL to make a request is listed in each endpoint's reference.

Path Parameters

indexName
string
required

Name of the index on which to perform the operation.

Example:

"ALGOLIA_INDEX_NAME"

Query Parameters

forwardToReplicas
boolean

Whether changes are applied to replica indices.

clearExistingRules
boolean

Whether existing rules should be deleted before adding this batch.

Body

application/json · object[]

Rules to add or replace.

Response

200
application/json

OK

Response, taskID, and update timestamp.